import 'package:flutter/material.dart';
import 'package:flutter_business_1803a/page/index_page.dart';
import 'package:flutter_business_1803a/provide/counter.dart';
import 'package:flutter_business_1803a/provide/provide_cart.dart';
import 'package:flutter_business_1803a/provide/provide_child_category.dart';
import 'package:flutter_business_1803a/provide/provide_detail_info.dart';
import 'package:flutter_business_1803a/router/application.dart';
import 'package:flutter_business_1803a/router/routers.dart';
import 'package:provide/provide.dart';
import 'package:fluro/fluro.dart';

void main() {
  ///使用Provide第二步,把所需要的Provide进行声明,没有声明是无法使用的
  var providers = Providers();
  var counter = Counter();
  var childCategory = ChildCategory();
  var detailInfo = DetailsInfoProvide();
  var cartProvide = CartProvide();
  providers
    ..provide(Provider<Counter>.value(counter)) //两个..代表构建者模式,类似于java中的build()
    ..provide(Provider<DetailsInfoProvide>.value(detailInfo))
    ..provide(Provider<CartProvide>.value(cartProvide))
    ..provide(Provider<ChildCategory>.value(childCategory));

  ///使用Provide第三步,修改runApp的模式
  runApp(ProviderNode(
    child: MyApp(),
    providers: providers,
  ));
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    final router = Router();
    Routes.configureRoutes(router);
    Application.router = router;
    return MaterialApp(
      title: '百姓生活+',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(primaryColor: Colors.pink),
      home: IndexPage(),
      onGenerateRoute: Application.router.generator,
    );
  }
}
